﻿using System;
using System.Text;

namespace HslCommunication.Robot.EFORT
{
	/// <summary>
	/// 埃夫特机器人的数据结构<br />
	/// The data structure of the efort robot
	/// </summary>
	// Token: 0x02000039 RID: 57
	public class EfortData
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x06000498 RID: 1176 RVA: 0x00012E28 File Offset: 0x00011028
		public EfortData()
		{
			this.IoDOut = new byte[32];
			this.IoDIn = new byte[32];
			this.IoIOut = new int[32];
			this.IoIIn = new int[32];
			this.DbAxisPos = new float[7];
			this.DbCartPos = new float[6];
			this.DbAxisSpeed = new float[7];
			this.DbAxisAcc = new float[7];
			this.DbAxisAccAcc = new float[7];
			this.DbAxisTorque = new float[7];
			this.DbAxisDirCnt = new int[7];
			this.DbAxisTime = new int[7];
		}

		/// <summary>
		/// 报文开始的字符串
		/// </summary>
		// Token: 0x170000E7 RID: 231
		// (get) Token: 0x06000499 RID: 1177 RVA: 0x00012EDD File Offset: 0x000110DD
		// (set) Token: 0x0600049A RID: 1178 RVA: 0x00012EE5 File Offset: 0x000110E5
		public string PacketStart { get; set; }

		/// <summary>
		/// 数据命令
		/// </summary>
		// Token: 0x170000E8 RID: 232
		// (get) Token: 0x0600049B RID: 1179 RVA: 0x00012EEE File Offset: 0x000110EE
		// (set) Token: 0x0600049C RID: 1180 RVA: 0x00012EF6 File Offset: 0x000110F6
		public ushort PacketOrders { get; set; }

		/// <summary>
		/// 数据心跳
		/// </summary>
		// Token: 0x170000E9 RID: 233
		// (get) Token: 0x0600049D RID: 1181 RVA: 0x00012EFF File Offset: 0x000110FF
		// (set) Token: 0x0600049E RID: 1182 RVA: 0x00012F07 File Offset: 0x00011107
		public ushort PacketHeartbeat { get; set; }

		/// <summary>
		/// 报警状态，1:有报警，0：无报警
		/// </summary>
		// Token: 0x170000EA RID: 234
		// (get) Token: 0x0600049F RID: 1183 RVA: 0x00012F10 File Offset: 0x00011110
		// (set) Token: 0x060004A0 RID: 1184 RVA: 0x00012F18 File Offset: 0x00011118
		public byte ErrorStatus { get; set; }

		/// <summary>
		/// 急停状态，1：无急停，0：有急停
		/// </summary>
		// Token: 0x170000EB RID: 235
		// (get) Token: 0x060004A1 RID: 1185 RVA: 0x00012F21 File Offset: 0x00011121
		// (set) Token: 0x060004A2 RID: 1186 RVA: 0x00012F29 File Offset: 0x00011129
		public byte HstopStatus { get; set; }

		/// <summary>
		/// 权限状态，1：有权限，0：无权限
		/// </summary>
		// Token: 0x170000EC RID: 236
		// (get) Token: 0x060004A3 RID: 1187 RVA: 0x00012F32 File Offset: 0x00011132
		// (set) Token: 0x060004A4 RID: 1188 RVA: 0x00012F3A File Offset: 0x0001113A
		public byte AuthorityStatus { get; set; }

		/// <summary>
		/// 伺服状态，1：有使能，0：未使能
		/// </summary>
		// Token: 0x170000ED RID: 237
		// (get) Token: 0x060004A5 RID: 1189 RVA: 0x00012F43 File Offset: 0x00011143
		// (set) Token: 0x060004A6 RID: 1190 RVA: 0x00012F4B File Offset: 0x0001114B
		public byte ServoStatus { get; set; }

		/// <summary>
		/// 轴运动状态，1：有运动，0：未运动
		/// </summary>
		// Token: 0x170000EE RID: 238
		// (get) Token: 0x060004A7 RID: 1191 RVA: 0x00012F54 File Offset: 0x00011154
		// (set) Token: 0x060004A8 RID: 1192 RVA: 0x00012F5C File Offset: 0x0001115C
		public byte AxisMoveStatus { get; set; }

		/// <summary>
		/// 程序运行状态，1：有运行，0：未运行
		/// </summary>
		// Token: 0x170000EF RID: 239
		// (get) Token: 0x060004A9 RID: 1193 RVA: 0x00012F65 File Offset: 0x00011165
		// (set) Token: 0x060004AA RID: 1194 RVA: 0x00012F6D File Offset: 0x0001116D
		public byte ProgMoveStatus { get; set; }

		/// <summary>
		/// 程序加载状态，1：有加载，0：无加载
		/// </summary>
		// Token: 0x170000F0 RID: 240
		// (get) Token: 0x060004AB RID: 1195 RVA: 0x00012F76 File Offset: 0x00011176
		// (set) Token: 0x060004AC RID: 1196 RVA: 0x00012F7E File Offset: 0x0001117E
		public byte ProgLoadStatus { get; set; }

		/// <summary>
		/// 程序暂停状态，1：有暂停，0：无暂停
		/// </summary>
		// Token: 0x170000F1 RID: 241
		// (get) Token: 0x060004AD RID: 1197 RVA: 0x00012F87 File Offset: 0x00011187
		// (set) Token: 0x060004AE RID: 1198 RVA: 0x00012F8F File Offset: 0x0001118F
		public byte ProgHoldStatus { get; set; }

		/// <summary>
		/// 模式状态，1:手动，2:自动，3:远程
		/// </summary>
		// Token: 0x170000F2 RID: 242
		// (get) Token: 0x060004AF RID: 1199 RVA: 0x00012F98 File Offset: 0x00011198
		// (set) Token: 0x060004B0 RID: 1200 RVA: 0x00012FA0 File Offset: 0x000111A0
		public ushort ModeStatus { get; set; }

		/// <summary>
		/// 读读状态，百分比（单位）
		/// </summary>
		// Token: 0x170000F3 RID: 243
		// (get) Token: 0x060004B1 RID: 1201 RVA: 0x00012FA9 File Offset: 0x000111A9
		// (set) Token: 0x060004B2 RID: 1202 RVA: 0x00012FB1 File Offset: 0x000111B1
		public ushort SpeedStatus { get; set; }

		/// <summary>
		/// IoDOut状态
		/// </summary>
		// Token: 0x170000F4 RID: 244
		// (get) Token: 0x060004B3 RID: 1203 RVA: 0x00012FBA File Offset: 0x000111BA
		// (set) Token: 0x060004B4 RID: 1204 RVA: 0x00012FC2 File Offset: 0x000111C2
		public byte[] IoDOut { get; set; }

		/// <summary>
		/// IoDIn状态
		/// </summary>
		// Token: 0x170000F5 RID: 245
		// (get) Token: 0x060004B5 RID: 1205 RVA: 0x00012FCB File Offset: 0x000111CB
		// (set) Token: 0x060004B6 RID: 1206 RVA: 0x00012FD3 File Offset: 0x000111D3
		public byte[] IoDIn { get; set; }

		/// <summary>
		/// IoIOut状态
		/// </summary>
		// Token: 0x170000F6 RID: 246
		// (get) Token: 0x060004B7 RID: 1207 RVA: 0x00012FDC File Offset: 0x000111DC
		// (set) Token: 0x060004B8 RID: 1208 RVA: 0x00012FE4 File Offset: 0x000111E4
		public int[] IoIOut { get; set; }

		/// <summary>
		/// IoIIn状态
		/// </summary>
		// Token: 0x170000F7 RID: 247
		// (get) Token: 0x060004B9 RID: 1209 RVA: 0x00012FED File Offset: 0x000111ED
		// (set) Token: 0x060004BA RID: 1210 RVA: 0x00012FF5 File Offset: 0x000111F5
		public int[] IoIIn { get; set; }

		/// <summary>
		/// 加载工程名
		/// </summary>
		// Token: 0x170000F8 RID: 248
		// (get) Token: 0x060004BB RID: 1211 RVA: 0x00012FFE File Offset: 0x000111FE
		// (set) Token: 0x060004BC RID: 1212 RVA: 0x00013006 File Offset: 0x00011206
		public string ProjectName { get; set; }

		/// <summary>
		/// 加载程序名
		/// </summary>
		// Token: 0x170000F9 RID: 249
		// (get) Token: 0x060004BD RID: 1213 RVA: 0x0001300F File Offset: 0x0001120F
		// (set) Token: 0x060004BE RID: 1214 RVA: 0x00013017 File Offset: 0x00011217
		public string ProgramName { get; set; }

		/// <summary>
		/// 错误信息
		/// </summary>
		// Token: 0x170000FA RID: 250
		// (get) Token: 0x060004BF RID: 1215 RVA: 0x00013020 File Offset: 0x00011220
		// (set) Token: 0x060004C0 RID: 1216 RVA: 0x00013028 File Offset: 0x00011228
		public string ErrorText { get; set; }

		/// <summary>
		/// 一到七轴的角度
		/// </summary>
		// Token: 0x170000FB RID: 251
		// (get) Token: 0x060004C1 RID: 1217 RVA: 0x00013031 File Offset: 0x00011231
		// (set) Token: 0x060004C2 RID: 1218 RVA: 0x00013039 File Offset: 0x00011239
		public float[] DbAxisPos { get; set; }

		/// <summary>
		/// X,Y,Z,A,B,C方向，也叫笛卡尔坐标系
		/// </summary>
		// Token: 0x170000FC RID: 252
		// (get) Token: 0x060004C3 RID: 1219 RVA: 0x00013042 File Offset: 0x00011242
		// (set) Token: 0x060004C4 RID: 1220 RVA: 0x0001304A File Offset: 0x0001124A
		public float[] DbCartPos { get; set; }

		/// <summary>
		/// 一到七轴的速度
		/// </summary>
		// Token: 0x170000FD RID: 253
		// (get) Token: 0x060004C5 RID: 1221 RVA: 0x00013053 File Offset: 0x00011253
		// (set) Token: 0x060004C6 RID: 1222 RVA: 0x0001305B File Offset: 0x0001125B
		public float[] DbAxisSpeed { get; set; }

		/// <summary>
		/// 一到七轴的加速度
		/// </summary>
		// Token: 0x170000FE RID: 254
		// (get) Token: 0x060004C7 RID: 1223 RVA: 0x00013064 File Offset: 0x00011264
		// (set) Token: 0x060004C8 RID: 1224 RVA: 0x0001306C File Offset: 0x0001126C
		public float[] DbAxisAcc { get; set; }

		/// <summary>
		/// 一到七轴的加加速度
		/// </summary>
		// Token: 0x170000FF RID: 255
		// (get) Token: 0x060004C9 RID: 1225 RVA: 0x00013075 File Offset: 0x00011275
		// (set) Token: 0x060004CA RID: 1226 RVA: 0x0001307D File Offset: 0x0001127D
		public float[] DbAxisAccAcc { get; set; }

		/// <summary>
		/// 一到七轴的力矩
		/// </summary>
		// Token: 0x17000100 RID: 256
		// (get) Token: 0x060004CB RID: 1227 RVA: 0x00013086 File Offset: 0x00011286
		// (set) Token: 0x060004CC RID: 1228 RVA: 0x0001308E File Offset: 0x0001128E
		public float[] DbAxisTorque { get; set; }

		/// <summary>
		/// 轴反向计数
		/// </summary>
		// Token: 0x17000101 RID: 257
		// (get) Token: 0x060004CD RID: 1229 RVA: 0x00013097 File Offset: 0x00011297
		// (set) Token: 0x060004CE RID: 1230 RVA: 0x0001309F File Offset: 0x0001129F
		public int[] DbAxisDirCnt { get; set; }

		/// <summary>
		/// 轴工作总时长
		/// </summary>
		// Token: 0x17000102 RID: 258
		// (get) Token: 0x060004CF RID: 1231 RVA: 0x000130A8 File Offset: 0x000112A8
		// (set) Token: 0x060004D0 RID: 1232 RVA: 0x000130B0 File Offset: 0x000112B0
		public int[] DbAxisTime { get; set; }

		/// <summary>
		/// 设备开机总时长
		/// </summary>
		// Token: 0x17000103 RID: 259
		// (get) Token: 0x060004D1 RID: 1233 RVA: 0x000130B9 File Offset: 0x000112B9
		// (set) Token: 0x060004D2 RID: 1234 RVA: 0x000130C1 File Offset: 0x000112C1
		public int DbDeviceTime { get; set; }

		/// <summary>
		/// 报文结束标记
		/// </summary>
		// Token: 0x17000104 RID: 260
		// (get) Token: 0x060004D3 RID: 1235 RVA: 0x000130CA File Offset: 0x000112CA
		// (set) Token: 0x060004D4 RID: 1236 RVA: 0x000130D2 File Offset: 0x000112D2
		public string PacketEnd { get; set; }

		/// <summary>
		/// 从之前的版本数据构造一个埃夫特机器人的数据类型
		/// </summary>
		/// <param name="data">真实的数据内容</param>
		/// <returns>转换的结果内容</returns>
		// Token: 0x060004D5 RID: 1237 RVA: 0x000130DC File Offset: 0x000112DC
		public static OperateResult<EfortData> PraseFromPrevious(byte[] data)
		{
			bool flag = data.Length < 784;
			OperateResult<EfortData> result;
			if (flag)
			{
				result = new OperateResult<EfortData>(string.Format(StringResources.Language.DataLengthIsNotEnough, 784, data.Length));
			}
			else
			{
				EfortData efortData = new EfortData();
				efortData.PacketStart = Encoding.ASCII.GetString(data, 0, 15).Trim();
				efortData.PacketOrders = BitConverter.ToUInt16(data, 17);
				efortData.PacketHeartbeat = BitConverter.ToUInt16(data, 19);
				efortData.ErrorStatus = data[21];
				efortData.HstopStatus = data[22];
				efortData.AuthorityStatus = data[23];
				efortData.ServoStatus = data[24];
				efortData.AxisMoveStatus = data[25];
				efortData.ProgMoveStatus = data[26];
				efortData.ProgLoadStatus = data[27];
				efortData.ProgHoldStatus = data[28];
				efortData.ModeStatus = BitConverter.ToUInt16(data, 29);
				efortData.SpeedStatus = BitConverter.ToUInt16(data, 31);
				for (int i = 0; i < 32; i++)
				{
					efortData.IoDOut[i] = data[33 + i];
				}
				for (int j = 0; j < 32; j++)
				{
					efortData.IoDIn[j] = data[65 + j];
				}
				for (int k = 0; k < 32; k++)
				{
					efortData.IoIOut[k] = BitConverter.ToInt32(data, 97 + 4 * k);
				}
				for (int l = 0; l < 32; l++)
				{
					efortData.IoIIn[l] = BitConverter.ToInt32(data, 225 + 4 * l);
				}
				efortData.ProjectName = Encoding.ASCII.GetString(data, 353, 32).Trim(new char[1]);
				efortData.ProgramName = Encoding.ASCII.GetString(data, 385, 32).Trim(new char[1]);
				efortData.ErrorText = Encoding.ASCII.GetString(data, 417, 128).Trim(new char[1]);
				for (int m = 0; m < 7; m++)
				{
					efortData.DbAxisPos[m] = BitConverter.ToSingle(data, 545 + 4 * m);
				}
				for (int n = 0; n < 6; n++)
				{
					efortData.DbCartPos[n] = BitConverter.ToSingle(data, 573 + 4 * n);
				}
				for (int num = 0; num < 7; num++)
				{
					efortData.DbAxisSpeed[num] = BitConverter.ToSingle(data, 597 + 4 * num);
				}
				for (int num2 = 0; num2 < 7; num2++)
				{
					efortData.DbAxisAcc[num2] = BitConverter.ToSingle(data, 625 + 4 * num2);
				}
				for (int num3 = 0; num3 < 7; num3++)
				{
					efortData.DbAxisAccAcc[num3] = BitConverter.ToSingle(data, 653 + 4 * num3);
				}
				for (int num4 = 0; num4 < 7; num4++)
				{
					efortData.DbAxisTorque[num4] = BitConverter.ToSingle(data, 681 + 4 * num4);
				}
				for (int num5 = 0; num5 < 7; num5++)
				{
					efortData.DbAxisDirCnt[num5] = BitConverter.ToInt32(data, 709 + 4 * num5);
				}
				for (int num6 = 0; num6 < 7; num6++)
				{
					efortData.DbAxisTime[num6] = BitConverter.ToInt32(data, 737 + 4 * num6);
				}
				efortData.DbDeviceTime = BitConverter.ToInt32(data, 765);
				efortData.PacketEnd = Encoding.ASCII.GetString(data, 769, 15).Trim();
				result = OperateResult.CreateSuccessResult<EfortData>(efortData);
			}
			return result;
		}

		/// <summary>
		/// 从新版本数据构造一个埃夫特机器人的数据类型
		/// </summary>
		/// <param name="data">真实的数据内容</param>
		/// <returns>转换的结果内容</returns>
		// Token: 0x060004D6 RID: 1238 RVA: 0x000134B8 File Offset: 0x000116B8
		public static OperateResult<EfortData> PraseFrom(byte[] data)
		{
			bool flag = data.Length < 788;
			OperateResult<EfortData> result;
			if (flag)
			{
				result = new OperateResult<EfortData>(string.Format(StringResources.Language.DataLengthIsNotEnough, 788, data.Length));
			}
			else
			{
				EfortData efortData = new EfortData();
				efortData.PacketStart = Encoding.ASCII.GetString(data, 0, 16).Trim();
				efortData.PacketOrders = BitConverter.ToUInt16(data, 18);
				efortData.PacketHeartbeat = BitConverter.ToUInt16(data, 20);
				efortData.ErrorStatus = data[22];
				efortData.HstopStatus = data[23];
				efortData.AuthorityStatus = data[24];
				efortData.ServoStatus = data[25];
				efortData.AxisMoveStatus = data[26];
				efortData.ProgMoveStatus = data[27];
				efortData.ProgLoadStatus = data[28];
				efortData.ProgHoldStatus = data[29];
				efortData.ModeStatus = BitConverter.ToUInt16(data, 30);
				efortData.SpeedStatus = BitConverter.ToUInt16(data, 32);
				for (int i = 0; i < 32; i++)
				{
					efortData.IoDOut[i] = data[34 + i];
				}
				for (int j = 0; j < 32; j++)
				{
					efortData.IoDIn[j] = data[66 + j];
				}
				for (int k = 0; k < 32; k++)
				{
					efortData.IoIOut[k] = BitConverter.ToInt32(data, 100 + 4 * k);
				}
				for (int l = 0; l < 32; l++)
				{
					efortData.IoIIn[l] = BitConverter.ToInt32(data, 228 + 4 * l);
				}
				efortData.ProjectName = Encoding.ASCII.GetString(data, 356, 32).Trim(new char[1]);
				efortData.ProgramName = Encoding.ASCII.GetString(data, 388, 32).Trim(new char[1]);
				efortData.ErrorText = Encoding.ASCII.GetString(data, 420, 128).Trim(new char[1]);
				for (int m = 0; m < 7; m++)
				{
					efortData.DbAxisPos[m] = BitConverter.ToSingle(data, 548 + 4 * m);
				}
				for (int n = 0; n < 6; n++)
				{
					efortData.DbCartPos[n] = BitConverter.ToSingle(data, 576 + 4 * n);
				}
				for (int num = 0; num < 7; num++)
				{
					efortData.DbAxisSpeed[num] = BitConverter.ToSingle(data, 600 + 4 * num);
				}
				for (int num2 = 0; num2 < 7; num2++)
				{
					efortData.DbAxisAcc[num2] = BitConverter.ToSingle(data, 628 + 4 * num2);
				}
				for (int num3 = 0; num3 < 7; num3++)
				{
					efortData.DbAxisAccAcc[num3] = BitConverter.ToSingle(data, 656 + 4 * num3);
				}
				for (int num4 = 0; num4 < 7; num4++)
				{
					efortData.DbAxisTorque[num4] = BitConverter.ToSingle(data, 684 + 4 * num4);
				}
				for (int num5 = 0; num5 < 7; num5++)
				{
					efortData.DbAxisDirCnt[num5] = BitConverter.ToInt32(data, 712 + 4 * num5);
				}
				for (int num6 = 0; num6 < 7; num6++)
				{
					efortData.DbAxisTime[num6] = BitConverter.ToInt32(data, 740 + 4 * num6);
				}
				efortData.DbDeviceTime = BitConverter.ToInt32(data, 768);
				efortData.PacketEnd = Encoding.ASCII.GetString(data, 772, 16).Trim();
				result = OperateResult.CreateSuccessResult<EfortData>(efortData);
			}
			return result;
		}
	}
}
